/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package flightlifter;

import java.nio.FloatBuffer;
import java.util.Vector;
import org.lwjgl.opengl.GL11;

/**
 *
 * @author Matt
 */
public class Wheel extends Node {

    private OrthoNormalBasis ONB;
    private MeshLoader meshLoader;


    public Wheel(OrthoNormalBasis ONB, MeshLoader meshLoader) {

        this.ONB = ONB;
        this.meshLoader = meshLoader;
    }

    @Override
    public void physics() {

    }

    @Override
    public void render(int mode) {


        if (selected == 1) {
            GL11.glColor3f(1.0f, 1.0f, 0.0f);
        } else {
            GL11.glColor3f(.75f, 0.75f, 0.75f);
        }



        GL11.glPushMatrix();
        PVector rot = ONB.front.pos;
        GL11.glTranslatef(rot.x, rot.y, rot.z);
        GL11.glColor4f(1, 1, 1, 1f);
        //GL11.glScalef(1,1,2);


        //I don't understand the code below.
        //it was a shot in the dark from
        //staring at the gluLookat code.
        //matrices are scary...it works

        //here be dragons

        PVector u = ONB.getUp();
        u.normalize();

        PVector r = ONB.getRight();
        r.normalize();

        PVector f = ONB.getForward();
        f.normalize();

        float[] temp = {r.x, r.y, r.z, 0,
            u.x, u.y, u.z, 0,
            f.x, f.y, f.z, 0,
            0, 0, 0, 1.f};

        FloatBuffer model = FlightLifter.allocFloats(temp);

        GL11.glMultMatrix(model);

        meshLoader.draw();

        GL11.glPopMatrix();
    }

    @Override
    public boolean dependsOn(Point p) {
        return false;
    }

    public String pickle(Vector<Node> nodes) {
        return "G,"
                + ONB.pickle(nodes);
    }

    @Override
    public PVector getCentroid() {
        return ONB.getCentroid();


    }

    @Override
    public PVector getScreenSpaceCentroid() {
        PVector tmp = getCentroid();
        float[] ret = GLProject.project(tmp.x, tmp.y, tmp.z);

        return new PVector(ret[0], ret[1], 0);

    }
}
